import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Login extends JFrame {
    public Login() {
        setTitle("登录");
        setSize(300, 150);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLayout(new GridLayout(3, 2));

        JLabel userLabel = new JLabel("用户名:");
        JTextField userText = new JTextField();
        JLabel passLabel = new JLabel("密码:");
        JPasswordField passText = new JPasswordField();
        JButton loginButton = new JButton("登录");

        add(userLabel);
        add(userText);
        add(passLabel);
        add(passText);
        add(loginButton);

        loginButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String username = userText.getText();
                String password = new String(passText.getPassword());
                if ("admin".equals(username) && "123123".equals(password)) {
                    JOptionPane.showMessageDialog(null, "登录成功!");
                } else {
                    JOptionPane.showMessageDialog(null, "用户名或密码错误!");
                }
            }
        });
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                new Login().setVisible(true);
            }
        });
    }
}
